<template>
  <div>
    <a-card :bordered="false">
      <a-row :gutter="8">

        <a-col >
          <div class="table-page-search-wrapper">

          </div>
          <div class="table-operator">
            <a-button v-if="addEnable" type="primary" icon="plus" @click="handleAdd()">新建</a-button>
            <a-dropdown v-if="removeEnable&&selectedRowKeys.length > 0">
              <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">删除</a-button>
            </a-dropdown>
          </div>
          <s-table
            size="default"
            ref="table"
            rowKey="id"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
            :columns="columns"
            :data="loadData"
          >
              <span slot="action" slot-scope="text, record">
                <a v-if="editEnabel" @click="deploy(record)">部署流程</a>
                <a v-if="editEnabel" @click="handleEdit(record)">编辑</a>
                <a-divider type="vertical"/>
                <a v-if="removeEnable" @click="delByIds([record.id])">删除</a>
              </span>
          </s-table>
        </a-col>

      </a-row>

    </a-card>
  </div>
</template>

<script>
    import {STable} from '@/components'
    import {getModelId, getModelList} from '@/api/activiti/model'
    import {checkPermission} from '@/utils/permissions'

    export default {
        name: "TableList",
        components: {
            STable,
        },
        data() {
            return {
                searchValue: '',
                expandedKeys: [],
                dataList: [],
                autoExpandParent: false,
                labelCol: {
                    xs: {span: 24},
                    sm: {span: 5}
                },
                wrapperCol: {
                    xs: {span: 24},
                    sm: {span: 16}
                },
                form: this.$form.createForm(this),
                mdl: {},
                // 高级搜索 展开/关闭
                advanced: false,
                // 查询参数
                queryParam: {},
                // 表头
                columns: [
                    // {
                    //   title: '栏目编号',
                    //   dataIndex: 'categoryId'
                    // },
                    {
                        title: '模型id',
                        dataIndex: 'id'
                    },
                    {
                        dataIndex: 'key', // 列字段名
                        title: '模型标识' // 列标题
                    },
                    {
                        dataIndex: 'name',
                        title: '模型名称'
                    },
                    {
                        dataIndex: 'version',
                        title: '版本号'
                    },
                    {
                        dataIndex: 'createTime',
                        title: '创建时间'
                    },
                    {
                        dataIndex: 'lastUpdateTime',
                        title: '最后更新时间'
                    },
                ],
                // 加载数据方法 必须为 Promise 对象
                loadData: parameter => {
                    return getModelList(Object.assign(parameter, this.queryParam))
                },
                selectedRowKeys: [],
                selectedRows: [],
                addEnable: checkPermission('activiti:model:add'),
                editEnabel: checkPermission('activiti:model:edit'),
                removeEnable: checkPermission('activiti:model:remove')
            }
        },
        methods: {
            onSelectChange (selectedRowKeys, selectedRows) {
                this.selectedRowKeys = selectedRowKeys
                this.selectedRows = selectedRows
            },
            handleAdd() {
                getModelId().then(res => {
                    location.href = '/activiti/modeler.html?modelId=' + res
                })

            },
            handleEdit(record) {
            },
            handleOk() {
                this.$refs.table.refresh(true)
                console.log('handleSaveOk')
            },
            delByIds(ids) {

            },
            deploy(record) {

            }
        }
    }
</script>

<style scoped>

</style>